package com.ruoyi.result.papers.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.result.papers.domain.ResultPapers;
import com.ruoyi.result.papers.domain.dto.ResultPapersDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 论文Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-13
 */
@Mapper
public interface ResultPapersMapper extends BaseMapper<ResultPapers>
{
    /**
     * 查询论文
     *
     * @param id 论文主键
     * @return 论文
     */
    public ResultPapers selectResultPapersById(Long id);

    /**
     * 查询论文列表
     *
     * @param resultPapers 论文
     * @return 论文集合
     */
    public List<ResultPapers> selectResultPapersList(ResultPapersDTO resultPapers);

    /**
     * 新增论文
     *
     * @param resultPapers 论文
     * @return 结果
     */
    public int insertResultPapers(ResultPapers resultPapers);

    /**
     * 修改论文
     *
     * @param resultPapers 论文
     * @return 结果
     */
    public int updateResultPapers(ResultPapers resultPapers);

    /**
     * 删除论文
     *
     * @param id 论文主键
     * @return 结果
     */
    public int deleteResultPapersById(Long id);

    /**
     * 批量删除论文
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultPapersByIds(Long[] ids);

    /**
     * 批量获取论文详细信息
     */
    List<ResultPapers> selectResultPapersByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_papers WHERE sync_status = '是' AND is_deleted = 0")
    long selectCountNumber();


    @Select("SELECT YEAR(publish_date) as year, COUNT(*) as count FROM result_papers " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(publish_date) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(publish_date) as year, COUNT(*) as count FROM result_papers " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(publish_date) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);

    List<ResultPapers> selectResultPapersListByDept(ResultPapersDTO resultPapers);
}
